#define _GNU_SOURCE
#include <pthread.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>

static void *thread_func1(void *arg)
{   int i = 0;
     while(1)
    {
        printf("thread_func 111 tid: %d \n",gettid());
        sleep(1);
        if(i++==10)
        {
            return NULL;
        }
    }
    return NULL;
}

static void *thread_func2(void *arg)
{   
     int i = 0; 
    while(1)
    {
        printf("thread_func 222 tid:%d \n",gettid());
        sleep(1);

        if(i++==15)
        {
            return NULL;
        }
    }
    return NULL;

}


int main(int argc, char const *argv[])
{
    pthread_t thread1,thread2;
    pthread_create(&thread1,NULL,thread_func1,NULL);
    pthread_create(&thread2,NULL,thread_func2,NULL);
 //   int i = 0;
    // while(1)
    // {
    //     i++;
    //     sleep(1);
    //     if(i==10)
    //     {
    //         pthread_cancel(thread1);
    //         pthread_cancel(thread2);
    //         printf("cancel thread1 and thread2\n");


    //     }

    // }
    pthread_join(thread1,NULL);//等待子线程结束
    printf("thread1 end\n");
    pthread_join(thread2,NULL);
    printf("thread2 end\n");


    
    return 0;
}
